"""登录页面"""
from PO.utils import DriverUtil


class LoginPage:
    """登录对象层"""

    def __init__(self):
        self.driver = DriverUtil.get_driver()

    def find_username(self):
        """定位用户名方法"""
        return self.driver.find_element("id", "username")

    def find_password(self):
        """定位密码方法"""
        return self.driver.find_element("id", "password")

    def find_verify_code(self):
        return self.driver.find_element("id", "verify_code")

    def find_login_button(self):
        return self.driver.find_element("class name", "login_bnt")


class LoginHandle:
    """登陆操作层"""

    def __init__(self):
        self.login_page = LoginPage()

    def input_account(self, username):
        self.login_page.find_username().send_keys(username)

    def input_password(self, password):
        self.login_page.find_password().send_keys(password)

    def input_verify_code(self, verify):
        self.login_page.find_verify_code().send_keys(verify)

    def click_login_btn(self):
        self.login_page.find_login_button().click()


class loginTask:
    """登录业务层"""

    def __init__(self):
        self.login_handle = LoginHandle()

    def success_login(self, username, password, code):
        self.login_handle.input_account(username)
        self.login_handle.input_password(password)
        self.login_handle.input_verify_code(code)
        self.login_handle.click_login_btn()
